//创建追杀直升机 by k1

_tag = _this; //selectRandom (call A3E_fnc_GetPlayers - Escape_Players_enemy)
_pos = [_tag, 800, 2000,1,1] call BIS_fnc_findSafePos;
_arr = [_pos, 0, (selectRandom a3e_arr_O_attack_heli), A3E_VAR_Side_Opfor] call BIS_fnc_spawnVehicle;
_veh = _arr select 0; //载具
_crew = _arr select 1;
_grp = _arr select 2;
Escape_air_killer pushback _veh;

{[_x,.8] call Escape_setSkills} forEach _crew;

//systemchat format["创建追杀直升机. 追杀载具总计%1架", {alive _x} count Escape_air_killer];

_h = round(random 150);
if (_h < 55) then {_h = 55};
_veh flyInHeight _h;

_veh doMove (getPos _tag);
_grp setSpeedMode (selectRandom ["LIMITED","NORMAL","FULL"]);

_veh reveal _tag;
_veh commandTarget _tag;
_veh commandFire _tag;
//_veh doTarget _tag;
//_veh doFire _tag;

_veh spawn {
	_t = time + 600; //
	waitUntil {sleep 3; (!alive _this || {time > _t && {{_this distance2D _x < 999} count (call A3E_fnc_GetPlayers - Escape_Players_enemy) == 0}})};
	_this setDamage 1;
};

[_veh, _grp] spawn {
	params ["_veh", "_grp"];
	sleep 30;
	waitUntil {
		_pos = getPosASL _veh;
		sleep ([3, 6] call BIS_fnc_randomInt);
		if (!alive _veh || {!alive (driver _veh)} || {(getpos _veh select 2) < 1}) exitWith {true};
		if (_pos distance2D getPosASL _veh < 1) then [{
			if (_veh getVariable ["DB_heli_hover", 0] > 4) then [{
				_veh call DB_hel_debug;
			},{
				_ply = _veh call Escape_minDisUnit;
				if (alive _ply) then {
					_dir = _veh getDir _ply;
					_pos = if(([0, 1] call BIS_fnc_randomInt) == 1)then[{_ply getPos [([500, 999] call BIS_fnc_randomInt), _dir]},{_ply getPos [([-50, -100] call BIS_fnc_randomInt), _dir]}];
					_veh doMove _pos;
					_grp setSpeedMode (selectRandom ["LIMITED","NORMAL","FULL"]);
					_veh reveal _ply;
					_veh commandTarget _ply;
					_veh commandFire _ply;
				};
				_veh setVariable ["DB_heli_hover", (_veh getVariable ["DB_heli_hover", 0]) + 1];
			}];
		},{
			if (_veh getVariable ["DB_heli_hover", 0] > 0) then {_veh setVariable ["DB_heli_hover", 0]};
		}];
		false
	};
}; ////
sleep 2;


